<template>
  <div class="body">
    <el-form class="form" :model="form" v-loading="loading.form" size="mini">
      <el-form-item
        :rules="[{ required: true, message: '名字不能为空' }]"
        label="名字"
        :label-width="fromViewCofing.label_width"
      >
        <el-input v-model="form.name" class="inp"></el-input>
      </el-form-item>
      <div class="form_footer">
        <el-button type="success" @click="fromSubmit">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import { apiOrganizationbBsinessOrganizationSelect } from "@/api/apiCommon";
export default {
  name: "Index",
  data() {
    return {
      init_form: {
        id: 0,
      },
      form: {},
      fromViewCofing: {
        input_width: "120px",
        label_width: "160px",
      },
      loading: {
        dialog_create: false,
        table: false,
        form: false,
      },
    };
  },
  created() {
    var params = this.$route.query;
    if (params.id != 0) {
      this.req_details(params.id);
    }

  },
  methods: {
    /**表单提交 */
    fromSubmit() {
      const _this = this;
      _this.loading_start("form");
      var form = this.form;
      console.log(form, "form");
      var reqData = {};
      reqData.id = form.id;
      reqData.logo_img = form.logo_img;
      reqData.name = form.name;
      apiOrganizationCreate(reqData)
        .then((response) => {
          if (response.code == 1) {
          } else {
            _this.$message.error(response.msg);
          }
          _this.loading_end("form");
        })
        .catch(function (result) {
          _this.loading_end("form");
        });
    },
    // 获取详情
    req_details(id) {
      const _this = this;
      _this.loading_start("form");
      if (!id) {
        return;
      }
      apiOrganizationDetails({
        id: id,
      })
        .then((response) => {
          const result = response.data.details;
          if (response.code == 1) {
          } else {
            _this.$message.error(response.msg);
          }
          _this.loading_end("form");
        })
        .catch(function (result) {
          _this.loading_end("form");
        });
    },
    // 加载开始...
    loading_start(keys) {
      if (Array.isArray(keys)) {
        keys.forEach((key) => {
          this.loading[key] = true;
          setTimeout(() => {
            this.loading[key] = false;
          }, 5000);
        });
      } else {
        this.loading[keys] = true;
        setTimeout(() => {
          this.loading[keys] = false;
        }, 5000);
      }
    },
    // 加载结束...
    loading_end(keys) {
      if (Array.isArray(keys)) {
        keys.forEach((key) => {
          this.loading[key] = false;
        });
      } else {
        this.loading[keys] = false;
      }
    },
  },
};
</script>

<style lang="scss"></style>
